<?php

/*
  VoIP Wholesale 1.0
  ------------------
  Document   : module_mod_settings
  Created on : Sep 25, 2011, 1:28:26 PM
  Author     : Milos Jovanovic <miloscode@gmail.com>
  Description:

 */
class Module_mod_settings extends MY_Model {
    
    function __construct() {
        parent::__construct();

		$this->MODULE->config->load('module_config');	
		$this->MODULE->short_name = $this->MODULE->config->item('short_name');
		$this->MODULE->settings_table = $this->MODULE->config->item('settings_table');	 		
    }
	
public function get_all_settings_from_db()
{
	$query = $this->db->get($this->MODULE->settings_table);
	
	foreach($query->result_array() as $entry)
	{
		$result[$entry['name']] = $entry['value'];
	}
	
	return $result;
}


public function get_setting_item_from_db($item_name)
{
	$query = $this->db->where('name',$item_name)->get($this->MODULE->settings_table);
	
	$entry = $query->row_array();
	
	$result = $entry['value'];
	
	return $result;
}

public function save_settings($post)
{	
	foreach($post as $variable => $value)
	{
		$data['name'] = $variable;	
		$data['value'] = $value;	
		
		$this->db->where('name',$variable)->update($this->MODULE->settings_table,$data);
	}
	
	return "true|".lang('msg_settings_saved_successfully');	
}

}
?>
